<template>
	<view>
		<!-- 刷题未解锁 -->
		<u-popup :show="jsshow" :round="10" mode="center" @close="jsclose">
			<view class="tanchuk">
				<view class="jiesuo">
					<image src="../../static/image/system/jiesuo.png" mode=""></image>
				</view>
				<view class="gongneng">
					<view class="weijs">还未解锁刷题功能哦~</view>
					<view class="timu">解锁刷题功能海量题目等你来学</view>
					<view class="qugoumai" @click="gobuy">去购买</view>
					<view class="quxiao" @click="quxiao">取消</view>
				</view>
			</view>
		</u-popup>
		<!-- 选择分类1 -->
		<view class="xuanzezhangjie">
			<view class="ffffff fuxi flexcenter margin_top box" v-for="item in list" :key="item.id"
				@click="jumpurl(item)">
				<view class="jichuban">{{item.name}}</view>
				<!-- <view class="icon">
					<image src="../../static/image/system/righticon.png" mode=""></image>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list: [],
				type: 1,
				show: false,
				jsshow: false,
			}
		},
		onLoad(options) {
			this.type = options.type
			this.getlist()
		},
		methods: {
			getlist() {
				httpRequest.request("/api/quizz_category/lists", 'POST', {}, false, false, true).then(res => {
					this.list = res.data
				})
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request("/api/quizz_category/lists", 'POST', {
					page: page || 1,
					pagesize: _this.limit
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// jumpurl(item) {
			// 	if (this.type == 3 || this.type == 4) {
			// 		uni.navigateTo({
			// 			url: "/pages/homepage/tingkeluanfu?id=" + item.id + "&type=" + this.type + "&name=" + item.name
			// 		})
			// 		return false
			// 	}
			// 	uni.navigateTo({
			// 		url: "/pages/homepage/tingke?id=" + item.id + "&type=" + this.type + "&name=" + item.name
			// 	})
			// },
			jumpurl(item) {
				httpRequest.request("/api/user/user_package", 'POST', {
					quizz_category_id: item.id
				}, false, false, true).then(res => {
					// let data = Date.parse(new Date())
					// console.log(data,'当前时间')
					// console.log(this.date(data),'当前时间')
					// console.log(res.data.package.expire_time,'刷题结束时间')
					// console.log(this.date(res.data.package.expire_time),'刷题结束时间')
					// if(data>=res.data.package.expire_time||!res.data.package.expire_time){
					if (res.data.status == 1 || res.data.status == 0) {
						this.jsshow = true
					} else {
						if (this.type == 3 || this.type == 4) {
							uni.navigateTo({
								url: "/pages/homepage/tingkeluanfu?id=" + item.id + "&type=" + this.type +
									"&name=" + item.name
							})
							return false
						}
						uni.navigateTo({
							url: "/pages/homepage/tingke?id=" + item.id + "&type=" + this.type + "&name=" +
								item.name
						})
						// if (this.type == 1) {
						// 	uni.navigateTo({
						// 		url: "/pages/homepage/xuanzezhangjie?id=" + id + "&type=" + this.type
						// 	})
						// } else {
						// 	uni.navigateTo({
						// 		url: '/pages/homepage/fuxims'
						// 	})
						// }
					}
				})
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day

				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			//取消
			quxiao() {
				this.jsshow = false;
			},
			//解锁刷题功能
			jsclose() {
				this.show = false
			},
			confirm() {
				this.show = false;
			},
			// 去购买
			gobuy() {
				uni.reLaunch({
					url: '/pages/mercharts/mercharts?current=' + 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fuxi {
		background: #DCB490;
		margin: 50rpx 70rpx 0;
		text-align: center;
		color: #fff;
		border-radius: 12rpx;
		padding: 40rpx;
	}

	.jichuban {
		font-size: 34rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
	}

	.icon {
		margin-bottom: 14rpx;
		width: 14rpx;
		height: 24rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.box {
		box-shadow: 0rpx 0rpx 15rpx 0rpx rgba(51, 51, 51, 0.0500);
	}


	.gongneng {
		padding: 57rpx 30rpx;
	}

	.jiesuo {
		width: 100%;
		height: 376.8rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.weijs {
		text-align: center;
		font-size: 36rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #333333;
	}

	.timu {
		font-size: 28rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #666666;
		text-align: center;
		margin: 20rpx 0 80rpx;
	}

	.qugoumai {
		font-size: 30rpx;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #FFFFFF;
		width: 555rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 93rpx;
		background: #DCB490;
		border-radius: 50rpx;
	}

	.quxiao {
		font-size: 28rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #666666;
		margin-top: 20rpx;
		text-decoration: underline #666666;
		text-align: center;
	}
</style>